%%% calculate spectrum
Fs = 1/0.00000000005;         
window = hann(40000); 
noverlap = 20000;    
nfft = 10240;        
signal=out.Spectrum_time_domian.signals(1).values;
       
[Pxx1, f] = pwelch(signal, window, noverlap, nfft, Fs);
% 
% %
% figure;
% plot(f, 10*log10(Pxx)); 
% xlabel('Frequency (Hz)');
% ylabel('Power Spectral Density (dB/Hz)');
% title('PSD via Welch Method');

signal=out.Spectrum_time_domian.signals(2).values;
[Pxx2, f] = pwelch(signal, window, noverlap, nfft, Fs);

signal=out.Spectrum_time_domian.signals(3).values;
[Pxx3, f] = pwelch(signal, window, noverlap, nfft, Fs);

signal=out.Spectrum_time_domian.signals(4).values;
[Pxx4, f] = pwelch(signal, window, noverlap, nfft, Fs);

signal=out.Spectrum_time_domian.signals(5).values;
[Pxx5, f] = pwelch(signal, window, noverlap, nfft, Fs);

signal=out.Spectrum_time_domian.signals(6).values;
[Pxx6, f] = pwelch(signal, window, noverlap, nfft, Fs);

Spectrum(:,1)=f;
Spectrum(:,2)=10*log10(Pxx1); % units of (dB/Hz)
Spectrum(:,3)=10*log10(Pxx2);
Spectrum(:,4)=10*log10(Pxx3);
Spectrum(:,5)=10*log10(Pxx4);
Spectrum(:,6)=10*log10(Pxx5);
Spectrum(:,7)=10*log10(Pxx6);

dlmwrite('Spectrum_data.txt', Spectrum, 'precision', '%.4e', 'delimiter', ' ');
% 


